<!DOCTYPE html>
<html lang="en">
<head>
    <title>注册</title>
    <meta charset="UTF-8">
    <#include "styleandscript.ftl"/>
    <script type="text/javascript">
        usernameReg = /([a-z]|[A-Z]|[0-9]|_|-|\\+|\\*|\/){1,16}/;
        pwdReg = /([a-z]|[A-Z]|[0-9]){8,16}/;

        function sub(form) {
            gEBI("error-name").innerText = "";
            gEBI("error-pwd").innerText = "";
            gEBI("error-pwd2").innerText = "";
            with (form) {
                if (username.value === "" || !usernameReg.test(username.value)) {
                    username.focus();
                    gEBI("error-name").innerText = "请输入1-16位大小写字母、符号（_-+*/）和数字";
                    return false;
                }
                if (!validate_required(pwd, gEBI("error-pwd"), "请输入密码！")) {
                    pwd.focus();
                    return false;
                }
                if (!validate_required(userpwd2, gEBI("error-pwd2"), "请输入密码！")) {
                    userpwd2.focus();
                    return false;
                }
                if (pwd.value === "" || pwd.value !== userpwd2.value) {
                    gEBI("error-pwd").innerText = "两次输入的密码不一致！";
                    return false;
                }
                if (pwd.value === "" || !pwdReg.test(pwd.value)) {
                    gEBI("error-pwd").innerText = "密码必须是8-16位大小写字母和数字组成！";
                    return false;
                }
                return true;
            }
        }
    </script>
</head>
<body>
<#import "/spring.ftl" as spring/>
<form action="/user/register" method="post" onsubmit="return sub(this);">
    <div style="width: auto; margin-left: auto; margin-right: auto;">
        <div style="width: 200px; margin-left: auto; margin-right: auto; margin-top: 100px;">
            <span class="error"><#if msg??>${msg}</#if></span>
        </div>
        <div style="width: 200px; margin-left: auto; margin-right: auto; margin-top: 100px;">
            <input id="username" type="text" placeholder="账号" name="name"
                   class="form-control"<#if user??> value="${user.name}" </#if>/>
            <span class="error" id="error-name"></span>
        </div>
        <div style="width: 200px; margin-left: auto; margin-right: auto; margin-top: 16px;">
            <input id="pwd" placeholder="密码" type="password" name="pwd" class="form-control"/>
            <span class="error" id="error-pwd"></span>
        </div>
        <div style="width: 200px; margin-left: auto; margin-right: auto; margin-top: 16px;">
            <input id="userpwd2" placeholder="密码" type="password" name="pwd2" class="form-control"/>
            <span class="error" id="error-pwd2"></span>
        </div>
        <div style="width: 200px; margin-left: auto; margin-right: auto; margin-top: 16px;">
            <input style="width: 100%; margin-left: auto; margin-right: auto;"
                   class="btn btn-primary" type="submit" value="注册"/>
        </div>
    </div>
</form>
</body>
</html>